package com.lson.filter;

import com.alibaba.fastjson.JSON;
import lombok.Builder;
import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class AuthFilter implements GlobalFilter , Ordered{


    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println(111);
        ServerHttpRequest request = exchange.getRequest();
        MultiValueMap<String, String> queryParams = request.getQueryParams();
        Flux<DataBuffer> body = request.getBody();
        int order = getOrder();
        System.out.println(order);

        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return -100;
    }

    public static void main(String[] args) {
        AuthFilter authFilter = new AuthFilter();
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("3");
        list.stream().distinct().forEach(x-> System.out.println(x));
        List<Integer> collect = list.stream().map(x -> new Integer(x)).collect(Collectors.toList());
        collect.forEach(x-> System.out.println(x.getClass()));


    }
}
